using UnityEngine;

namespace NJG
{
	public abstract class UIWorldMapBase : UIMapBase
	{
		private static UIWorldMapBase mInst;

		public MapTextManager mapTextManager;

		protected bool enableShowDistrict;

		public NJGMapItem destinationPoint;

		public static UIWorldMapBase inst
		{
			get
			{
				if (mInst == null)
				{
					mInst = Object.FindObjectOfType(typeof(UIWorldMapBase)) as UIWorldMapBase;
				}
				return mInst;
			}
		}

		public void InitInst()
		{
			mInst = this;
		}

		protected override void Awake()
		{
			inst.enabled = true;
			limitBounds = true;
			base.Awake();
		}

		protected override void OnStart()
		{
			base.OnStart();
			if (mChild == null)
			{
				mChild = base.cachedTransform.GetChild(0);
			}
			if (mChild == null)
			{
				mChild = base.transform;
			}
			if (calculateBorder)
			{
				mapBorderRadius = rendererTransform.localScale.x / 2f / 4f;
			}
			enableShowDistrict = true;
		}

		protected override void UpdateIcon(NJGMapItem item)
		{
			Vector2 pos = WorldToMap(item.cachedTransform.position);
			if (IsVisible(pos))
			{
				UIMapIconBase entry = GetEntry(item);
				if (entry != null && !entry.isValid)
				{
					SetIconPosition(entry);
					entry.isMapIcon = true;
					entry.isValid = true;
				}
			}
		}

		protected override void UpdateControls()
		{
			foreach (MapText mapText in mapTextManager.mapTexts)
			{
				mapText.UpdatePosition(WorldToMap(mapText.worldPosition));
			}
		}
	}
}
